#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include <stdio.h>
#include<fcntl.h>


int main()
{

    
   close(2);
   printf("stdin->fd: %d\n", stdin->_fileno);
   printf("stdout->fd: %d\n", stdout->_fileno);
   printf("stderr->fd: %d\n", stderr->_fileno);

        
    /*umask(0);
    // file descriptor: 文件描述符
    int fd1 = open("log1.txt", O_WRONLY|O_CREAT|O_APPEND, 0666);
    int fd2 = open("log2.txt", O_WRONLY|O_CREAT|O_APPEND, 0666);
    int fd3 = open("log3.txt", O_WRONLY|O_CREAT|O_APPEND, 0666);
    int fd4 = open("log4.txt", O_WRONLY|O_CREAT|O_APPEND, 0666);
    if(fd1 < 0)
    {
        printf("open file error\n");
        return 1;
    }
    printf("fd1: %d\n", fd1);
    printf("fd2: %d\n", fd2);
    printf("fd3: %d\n", fd3);
    printf("fd4: %d\n", fd4);

    // 取消注释可测试文件写入
    const char *message = "xxxx";
    write(fd1, message, strlen(message)); 
    write(fd2, message, strlen(message)); 
    write(fd3, message, strlen(message)); 
    write(fd4, message, strlen(message)); 

    close(fd1);
    close(fd2);
    close(fd3);
    close(fd4);
*/ 
    return 0;
}


/*int main()
{
  umask(0);
   int fd=open("log.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
   if(fd<0)
   {
     printf("open file error\n");
     return 1;
   }

   const char*message="hello file systrm call\n";
   write(fd,message,strlen(message));
   close(fd);
   return 0;
}*/


/*#define ONE (1<<0) // 1
#define TWO (1<<1) // 2
#define THREE (1<<2) // 4
#define FOUR (1<<3) // 8

void show(int flags)
{
    if(flags&ONE) printf("hello function1\n");
    if(flags&TWO) printf("hello function2\n");
    if(flags&THREE) printf("hello function3\n");
    if(flags&FOUR) printf("hello function4\n");
}

int main()
{
    show(ONE);
    show(TWO|FOUR);
    show(ONE|TWO);
    show(ONE|TWO|THREE);
    return 0;
}*/ 

/*int main()
{    
    //chdir("/home/zsf");
    printf("%d \n",getpid());
    FILE *fp=fopen("log.txt","a"); 
    if(fp==NULL)
    {
      perror("fopen");
      return 1;
    }

    const char*message="hello Linux message\n";
    fwrite(message,strlen(message),1,fp);
        
    fclose(fp);
    //sleep(1000);
    return 0;
}*/ 


